package com.msmall.community.common.action.html;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantAjax;
import com.msmall.base.util.ConstantDB;
import com.msmall.community.common.model.Commend;
import com.msmall.community.common.service.CommendManager;

public class CommendAction extends HTMLBaseAction{

	private static final long serialVersionUID = -5969524795702456650L;

	private Long commendId;
	
	/**
	 * 推荐来源类型  1:BBS 2Space 3问答 4知识
	 * ConstantDB.COMMEND_TYPE_
	 */
	private short type;
	/**
	 * 推荐的实体ID
	 */
	private Long eid;
	
	/**推荐等级
	 * 
	 */
	private short level;
	
	private Commend commend;
	
	private CommendManager commendManager;
	
	/**
	 * 创建一个新的推荐，需要审核， 不能使用
	 * @return
	 */
	public String execute(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE);
		try{
			commend = new Commend();
			commend.setCommendType(type);
			commend.setEntityId(eid);
			commend.setCommendLevel(level);
			commendManager.createCommend(commend, getUserid());
			
			buffer.append(ConstantAjax.RESULT_TRUE)
			.append(ConstantAjax.CONTENT_PRE)
			.append(getText("html.bbs.topic.commend.success"))
			.append(ConstantAjax.CONTENT_SUFF);
		}catch(Exception e){
			buffer.append(ConstantAjax.RESULT_FALSE)
			.append(ConstantAjax.CONTENT_PRE)
			.append(getText("html.bbs.topic.commend.error"))
			.append(ConstantAjax.CONTENT_SUFF);
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		if(ConstantDB.COMMEND_TYPE_BBS_TOPIC.compareTo(type) == 0){
			return "topic";
		}
		if(ConstantDB.COMMEND_TYPE_QUESTION.compareTo(type) == 0){
			return "question";
		}
		if(ConstantDB.COMMEND_TYPE_SPACE_BLOG.compareTo(type) == 0){
			return "space";
		}
		if(ConstantDB.COMMEND_TYPE_KLG.compareTo(type) == 0){
			return "klg";
		}
		return "";
	}
	
	public String remove(){
		commendManager.removeCommend(type, eid, getUserid());
		if(ConstantDB.COMMEND_TYPE_BBS_TOPIC.compareTo(type) == 0){
			return "topic";
		}
		if(ConstantDB.COMMEND_TYPE_QUESTION.compareTo(type) == 0){
			return "question";
		}
		if(ConstantDB.COMMEND_TYPE_SPACE_BLOG.compareTo(type) == 0){
			return "space";
		}
		return "";
	}

	public Long getCommendId() {
		return commendId;
	}

	public void setCommendId(Long commendId) {
		this.commendId = commendId;
	}

	public short getType() {
		return type;
	}

	public void setType(short type) {
		this.type = type;
	}

	public Long getEid() {
		return eid;
	}

	public void setEid(Long eid) {
		this.eid = eid;
	}

	public short getLevel() {
		return level;
	}

	public void setLevel(short level) {
		this.level = level;
	}

	public Commend getCommend() {
		return commend;
	}

	public void setCommend(Commend commend) {
		this.commend = commend;
	}

	public void setCommendManager(CommendManager commendManager) {
		this.commendManager = commendManager;
	}
	

}
